<template>
    <div class="sidebar">
        <el-menu :default-active="onRoutes" @select="handleSelect" class="el-menu-vertical-demo" theme="dark" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.subMenu">
                    <el-submenu :index="item.url">
                        <template slot="title"><i :class="item.icon"></i>{{ item.title }}</template>
                        <el-menu-item v-for="(subItem,i) in item.subMenu" :key="i" :index="subItem.url">{{ subItem.title}}
                        </el-menu-item>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.url">
                        <i :class="item.icon"></i>{{ item.title }}
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                items: [],
                menuOpthons:{
                    currentKey:'1'
                }
            }
        },
        methods: {
            handleSelect(key, keyPath){
                // console.log(key)
                // console.log(keyPath)
            },
            init() {
                this.get("/auth/menu/select_tree", "", true, "", (result) => {
                    this.items = result.data;
                })
            }
        },
        mounted() {
            this.init()
        },
        computed: {
            onRoutes() {
                // console.log(this.$route)
                return this.$route.path.replace('/', '');
            }
            
        }
    }
</script>

<style scoped>
    .sidebar {
        display: block;
        position: absolute;
        width: 250px;
        left: 0;
        top: 70px;
        bottom: 0;
        background: #2E363F;
    }

    .sidebar > ul {
        height: 100%;
    }
</style>
